﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.NetworkAnalyst;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        #region 全局变量

        int flag;
        IMapDocument m_MapDocument;
        public IMapControl4 o_mapControl = null;
        IToolbarMenu m_TocMapMenu = new ToolbarMenuClass();//控制集合
        IToolbarMenu m_TocLayerMenu = new ToolbarMenuClass();//控制图层       
        IActiveView pActiveView;
        IElement element = new LineElement();
        public static IMapControl3 m_mapControl = null;

        ClsPathFinder CPF;
        IWorkspaceFactory ipWorkspaceFactory;
        IWorkspace ipWorkspace;
        IFeatureWorkspace ipFeatureWorkspace;
        IFeatureDataset pFeatDataset;
        IPolyline pPolyline;
        IPoint pPoint = new PointClass();
        IPointCollection mPointCollection;
        IRgbColor pRGB = new RgbColorClass();  //节点颜色
        IRgbColor lRGB = new RgbColorClass();  //路线颜色
        IGraphicsContainer pGraphicC;
        #endregion

        public Form1()
        {
            InitializeComponent();
        }

        // 初始化
        private void Form1_Load(object sender, EventArgs e)
        {
            CPF = new ClsPathFinder();
            m_mapControl = (IMapControl3)axMapControl1.Object;
            addMap();

            ICommand command1 = new CreateNewDocument();
            command1.OnCreate(m_mapControl.Object);
            command1.OnClick();
            string sFilePath = System.Windows.Forms.Application.StartupPath + "\\data\\map.mxd";
            axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing);

            pRGB.Red = 96;
            pRGB.Blue = 192;
            pRGB.Green = 24;

            lRGB.Red = 96;
            lRGB.Blue = 192;
            lRGB.Green = 24;
        }

        // 地图放大命令
        private void 放大ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 1;
        }

        // 地图缩小命令
        private void 缩小ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 2;
        }

        // 地图移动命令
        private void 移动ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 3;
        }

        // 更新鹰眼地图显示范围
        private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
        {
            IEnvelope pEnv;
            pEnv = e.newEnvelope as IEnvelope;
            IGraphicsContainer pGraphicsContainer;
            IActiveView pActiveView;
            pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
            pActiveView = pGraphicsContainer as IActiveView;
            pGraphicsContainer.DeleteAllElements();//'获取矩形坐标
            IRectangleElement pRectangleEle;
            pRectangleEle = new RectangleElementClass();
            IElement pEle;
            pEle = pRectangleEle as IElement;
            pEle.Geometry = pEnv;

            IRgbColor pColor;
            pColor = new RgbColorClass();
            pColor.RGB = 255;
            pColor.Transparency = 255;
            ILineSymbol pOutline;
            pOutline = new SimpleLineSymbolClass();
            pOutline.Width = 1;
            pOutline.Color = pColor;
            pColor = new RgbColorClass();
            pColor.RGB = 255;
            pColor.Transparency = 0;

            IFillSymbol pFillSymbol;
            pFillSymbol = new SimpleFillSymbolClass();
            pFillSymbol.Color = pColor;
            pFillSymbol.Outline = pOutline;
            //构建矩形元素
            IFillShapeElement pFillshapeEle;
            pFillshapeEle = pEle as IFillShapeElement;
            pFillshapeEle.Symbol = pFillSymbol;
            pEle = pFillshapeEle as IElement;
            pGraphicsContainer.AddElement(pEle, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }

        // 地图数据更新
        private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
        {
            IMap pMap= axMapControl1.Map;
            axMapControl2.Map.ClearLayers();
            comboBox1.Items.Clear();
            comboBox2.Items.Clear();
            for (int i = pMap.LayerCount - 1; i > -1; i--)
            {
                axMapControl2.Map.AddLayer(pMap.get_Layer(i));
            }

            for (int i = 0; i < pMap.LayerCount; i++)
            {
                comboBox1.Items.Add(pMap.get_Layer(i).Name);
                comboBox1.SelectedIndex = 0;

                comboBox2.Items.Add(pMap.get_Layer(i).Name);
                comboBox2.SelectedIndex = 0;
            }
        }

        // 地图点击事件
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            // 放大
            if (flag == 1)
            {
                axMapControl1.Extent = axMapControl1.TrackRectangle();
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
                // 缩小
            else if (flag == 2)
            {
                axMapControl1.TrackRectangle();
                IEnvelope pEnv = axMapControl1.Extent;
                pEnv.Expand(2, 2, true);
                axMapControl1.Extent = pEnv;
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
                // 移动
            else if (flag == 3)
                axMapControl1.Pan();
                // 空间查询
            else if (flag == 4)
            {
                axMapControl1.Map.ClearSelection();
                axMapControl1.CurrentTool = null;
                this.axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
                IGeometry pGeometry = this.axMapControl1.TrackPolygon();
                IFeatureLayer pFeatureLayer = this.axMapControl1.get_Layer(comboBox2.SelectedIndex) as IFeatureLayer;
                List<IFeature> pFList = this.GetSearchFeatures(pFeatureLayer, pGeometry);
                if (pFList.Count > 0)
                {
                    AttributesForm pAttributeForm = new AttributesForm();
                    pAttributeForm.dataGridView1.RowCount = pFList.Count + 1;
                    //设置边界风格
                    pAttributeForm.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken;
                    //设置列数
                    pAttributeForm.dataGridView1.ColumnCount = pFList[0].Fields.FieldCount;
                    for (int m = 0; m < pFList[0].Fields.FieldCount; m++)
                    {
                        pAttributeForm.dataGridView1.Columns[m].HeaderText = pFList[0].Fields.get_Field(m).AliasName;
                    }
                    //遍历要素
                    for (int i = 0; i < pFList.Count; i++)
                    {
                        IFeature pFeature = pFList[i];
                        for (int j = 0; j < pFeature.Fields.FieldCount; j++)
                        {
                            pAttributeForm.dataGridView1[j, i].Value = pFeature.get_Value(j).ToString();
                        }
                    }
                    axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                    pAttributeForm.Show();
                }
                else {
                    MessageBox.Show("未查询到数据");
                }
            }
            //距离测量
            else if (flag == 5)
            {
                this.axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
                IPolyline pPolyline = null;
                pPolyline = (IPolyline)axMapControl1.TrackLine();
                double l;
                l = Math.Abs(Math.Round(pPolyline.Length * ((long)this.axMapControl1.MapScale), 2));
                MessageBox.Show("量测的距离为" + l.ToString() + "米。");
                flag = 0;
            }
            //面积测量
            else if (flag == 6)
            {
                this.axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
                IPolygon pPolygon = null;
                pPolygon = (IPolygon)axMapControl1.TrackPolygon();
                IArea pArea = (IArea)pPolygon;
                double s;
                s = Math.Abs(Math.Round(pArea.Area * ((long)this.axMapControl1.MapScale) * ((long)this.axMapControl1.MapScale), 2));
                MessageBox.Show("量测的面积为" + s.ToString() + "平方米。");
                flag = 0;
            } //添加目的地
            else if (flag == 7)
            {
                axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                if (e.button == 1)
                {
                    IPoint pNewPoint = new PointClass();
                    pNewPoint.PutCoords(e.mapX, e.mapY);

                    drawPoint(pNewPoint.X, pNewPoint.Y);
                    if (mPointCollection == null)
                    {
                        mPointCollection = new MultipointClass();
                    }
                    object before = Type.Missing;
                    object after = Type.Missing;
                    mPointCollection.AddPoint(pNewPoint, ref before, ref after);
                }
            }else if(flag == 8){
                IActiveView pAV = axMapControl1.ActiveView;
                //创建点的几何对象
                IPoint pPoint = new PointClass();
                pPoint.X = e.mapX;
                pPoint.Y = e.mapY;
                //创建点的符号样式
                ISimpleMarkerSymbol pMarkerSymbol;
                pMarkerSymbol = new SimpleMarkerSymbolClass();
                pMarkerSymbol.Size = 7;
                pMarkerSymbol.Color = getRGB(96, 24, 192);
                pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                //创建点元素，将点几何对象，及符号样式值
                IMarkerElement pMarkerElement = new MarkerElementClass();
                IElement pElement = pMarkerElement as IElement;
                pElement.Geometry = pPoint as IGeometry;
                tagGeometry = pPoint as IGeometry;
                pMarkerElement.Symbol = pMarkerSymbol;
                pGraphicsContainer = axMapControl1.Map as IGraphicsContainer;
                pGraphicsContainer.AddElement(pElement, 0);
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }

        IGraphicsContainer pGraphicsContainer;
        IGeometry tagGeometry;

        private IRgbColor getRGB(int r, int g, int b)
        {
            IRgbColor pColor;
            pColor = new RgbColorClass();
            pColor.Red = r;
            pColor.Green = g;
            pColor.Blue = b;
            return pColor;
        }

        protected void drawPoint(double ex, double ey)
        {
            pPoint.X = ex;
            pPoint.Y = ey;
            ISimpleMarkerSymbol pMarkerSymbol;
            pMarkerSymbol = new SimpleMarkerSymbol();
            pMarkerSymbol.Size = 9;
            pMarkerSymbol.Color = pRGB;
            pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
            IMarkerElement pMarkerElement = new MarkerElementClass();
            IElement pElement = pMarkerElement as IElement;
            pElement.Geometry = pPoint as IGeometry;
            pMarkerElement.Symbol = pMarkerSymbol;
            pGraphicC = axMapControl1.Map as IGraphicsContainer;
            pGraphicC.AddElement(pElement, 0);
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }

        // 解析查询要素
        private List<IFeature> GetSearchFeatures(IFeatureLayer pFeatureLayer, IGeometry pGeometry)
        {
            try
            {
                List<IFeature> pFeatureList = new List<IFeature>();
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                IQueryFilter pQueryFilter = pSpatialFilter as IQueryFilter;
                pSpatialFilter.Geometry = pGeometry;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pQueryFilter, false);
                IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
                pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                IFeature pFeature = pFeatureCursor.NextFeature();
                while (pFeature != null)
                {
                    pFeatureList.Add(pFeature);
                    pFeature = pFeatureCursor.NextFeature();
                }
                return pFeatureList;
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return null;
            }
        }

        // 鼠标移动
        private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            if (e.button == 1)
            {
                IActiveView pAV = axMapControl1.ActiveView;
                IScreenDisplay pSD = pAV.ScreenDisplay;
                IPoint pPt = new PointClass();
                pPt.PutCoords(e.mapX, e.mapY);
                pSD.RotateMoveTo(pPt);
                pSD.RotateTimer();
            }
            scale.Text = "当前比例尺：1 :" + ((long)this.axMapControl1.MapScale).ToString();
            position.Text = " 鼠标位置：X = " + e.mapX.ToString() + " Y = " + e.mapY.ToString() + " " + this.axMapControl1.MapUnits.ToString().Substring(4);
        }

        // 鹰眼框选操作
        private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IEnvelope pEnv = axMapControl2.TrackRectangle();
            axMapControl1.Extent = pEnv;
            axMapControl1.Refresh();
        }

        // 空间查询
        private void 多边形查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 4;
        }

        // 清除查询结果
        private void 清除查询结果ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 0;
            IActiveView pActiveView = axMapControl1.ActiveView;
            for (int i = 0; i < axMapControl1.LayerCount; i++)
            {
                IFeatureLayer pFeaturelayer = axMapControl1.get_Layer(i) as IFeatureLayer;
                ClearSelectedMapFeatures(pActiveView, pFeaturelayer);
            }
        }

        // 清除查询
        public void ClearSelectedMapFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer)
        {
            if (activeView == null || featureLayer == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection;
            activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
            featureSelection.Clear();
        }

        // 属性查询
        private void 属性查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            queryForm qf = new queryForm(axMapControl1);
            qf.Show();
        }

        // 全图
        private void 全图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axMapControl1.Extent = axMapControl1.FullExtent;
        }

        private void 长度测量ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 5;
        }

        private void 面积测量ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 6;
        }

        public IFeatureWorkspace pFWorkspace;

        private void 打开鹰眼ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (axMapControl2.Visible == false)
            {
                axMapControl2.Visible = true;
                打开鹰眼ToolStripMenuItem.Text = "关闭鹰眼";
            }
            else {
                axMapControl2.Visible = false;
                打开鹰眼ToolStripMenuItem.Text = "打开鹰眼";
            }
        }

        private void 打开地图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Open Map Document";
            openFileDialog1.Filter = "Map Documents (*.mxd)|*.mxd";
            openFileDialog1.ShowDialog();
            string sFilePath = openFileDialog1.FileName;
            if (axMapControl1.CheckMxFile(sFilePath))
            { axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing); }
            else
            {
                MessageBox.Show(sFilePath + " is not a valid ArcMap document");
                return;
            }
        }

        private void 保存地图ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ICommand command = new ControlsSaveAsDocCommand();
            command.OnCreate(m_mapControl);
            command.OnClick();
        }

        private void 另存为图片ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //把地图保存为图片
            IHookHelper map_hookHelper = new HookHelperClass();
            //参数赋值  
            map_hookHelper.Hook = m_mapControl.Object;
            FrmExportMap frmExportDlg = new FrmExportMap(map_hookHelper);
            frmExportDlg.Show();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void 服务区分析ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            panel1.Visible = true;
        }

        private void 添加shpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string fullFilePath;
            //设置OpenFileDialog的属性，使其能打开多种类型文件  
            OpenFileDialog openFile = new OpenFileDialog();
            openFile.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*";
            openFile.Title = "打开文件";
            try
            {

                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    fullFilePath = openFile.FileName;
                    //获得文件路径  
                    int index = fullFilePath.LastIndexOf("\\");
                    string filePath = fullFilePath.Substring(0, index);
                    //获得文件名称  
                    string fileNam = fullFilePath.Substring(index + 1);
                    //加载shape文件  
                    if (openFile.FilterIndex == 1)
                    {
                        //打开工作空间工厂  
                        IWorkspaceFactory workspcFac = new ShapefileWorkspaceFactory();
                        IFeatureWorkspace featureWorkspc;
                        IFeatureLayer featureLay = new FeatureLayerClass();
                        //打开路径  
                        featureWorkspc = workspcFac.OpenFromFile(filePath, 0) as IFeatureWorkspace;
                        //打开类要素  
                        featureLay.FeatureClass = featureWorkspc.OpenFeatureClass(fileNam);
                        //清空图层  
                        axMapControl1.ClearLayers();
                        //添加图层  
                        axMapControl1.AddLayer(featureLay);
                        axMapControl1.Refresh();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }


        // 添加道路数据
        private void addMap()
        {
            axMapControl1.Map.ClearLayers();
            string path = System.Windows.Forms.Application.StartupPath;
            ipWorkspaceFactory = new AccessWorkspaceFactoryClass();
            string str = System.Environment.CurrentDirectory;
            ipWorkspace = ipWorkspaceFactory.OpenFromFile(path + "\\data\\road.mdb", 0);
            ipFeatureWorkspace = ipWorkspace as IFeatureWorkspace;
            pFeatDataset = ipFeatureWorkspace.OpenFeatureDataset("road");
            CPF.SetOrGetMap = axMapControl1.Map;
            CPF.OpenFeatureDatasetNetwork(pFeatDataset);

        }

        private void 目的地添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 7;
        }

        private void 生成车辆路线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lRGB.Red = 96;
            lRGB.Blue = 192;
            lRGB.Green = 24;
            getRoad("weight", lRGB);
        }

        private void getRoad(string weight,IRgbColor lRGB) {
            flag = 0;
            CPF.StopPoints = mPointCollection;
            CPF.SolvePath(weight);
            pPolyline = CPF.PathPolyLine();
            ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass();
            pLineSymbol.Color = lRGB;
            pLineSymbol.Width = 4;
            pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            ILineElement pPolylineEle = new LineElementClass();
            pPolylineEle.Symbol = pLineSymbol;
            IElement pEle = pPolylineEle as IElement;
            pEle.Geometry = pPolyline;
            pGraphicC = axMapControl1.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器
            pGraphicC.AddElement(pEle, 0);//把刚刚的element转到容器上
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerArrow;
        }

        private void 清除路线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (mPointCollection != null)
            {
                flag = 0;
                int count = mPointCollection.PointCount;
                mPointCollection.RemovePoints(0, count);
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                clearline();
            }
            else
            {
                MessageBox.Show("尚未计算路径，请计算后再清除！", "提示");
                return;
            }
        }

        //清除路径
        private void clearline()
        {
            this.axMapControl1.MousePointer = esriControlsMousePointer.esriPointerArrow;
            pGraphicC.DeleteAllElements();
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            axMapControl1.Refresh();
        }

        private void 按照距离规划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lRGB.Red = 96;
            lRGB.Blue = 192;
            lRGB.Green = 24;
            getRoad("weight1", lRGB);
        }

        private void 按照时间规划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lRGB.Red = 196;
            lRGB.Blue = 92;
            lRGB.Green = 24;
            getRoad("weight2", lRGB);
        }

        private void 按照费用规划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lRGB.Red = 196;
            lRGB.Blue = 192;
            lRGB.Green = 24;
            getRoad("weight3", lRGB);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            flag = 8;
        }
        IGeometry poiBufGeometry;
        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox2.Text != "")
            {
                double dis = Convert.ToDouble(textBox2.Text)/100000;
                pGraphicsContainer = axMapControl1.Map as IGraphicsContainer;    //定义容器

                ITopologicalOperator pTopoOperator = tagGeometry as ITopologicalOperator; //QI到拓扑操作
                IGeometry pBufferGeo = pTopoOperator.Buffer(dis);     //缓冲区分析

                ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                pFillSymbol.Color = getRGB(0, 230, 0);
                pFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                poiBufGeometry = pBufferGeo;

                PolygonElement aElement = new PolygonElement();
                aElement.Geometry = pBufferGeo;
                aElement.Symbol = pFillSymbol;
                aElement.Opacity = 50;

                pGraphicsContainer.AddElement(aElement, 0); //显示缓冲区
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                axMapControl1.ActiveView.Refresh();

                getBufferResult(pBufferGeo);
            }
            else
            {
                MessageBox.Show("范围数据为空，无法计算");
            }
        }


        private void getBufferResult(IGeometry pGeometry)
        {
            IFeatureLayer pFeatureLayer = this.axMapControl1.get_Layer(comboBox1.SelectedIndex) as IFeatureLayer;
            List<IFeature> pFList = this.GetSearchFeatures(pFeatureLayer, pGeometry);
            if (pFList.Count > 0)
            {
                AttributesForm pAttributeForm = new AttributesForm();
                pAttributeForm.dataGridView1.RowCount = pFList.Count + 1;
                //设置边界风格
                pAttributeForm.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken;
                //设置列数
                pAttributeForm.dataGridView1.ColumnCount = pFList[0].Fields.FieldCount;
                for (int m = 0; m < pFList[0].Fields.FieldCount; m++)
                {
                    pAttributeForm.dataGridView1.Columns[m].HeaderText = pFList[0].Fields.get_Field(m).AliasName;
                }
                //遍历要素
                for (int i = 0; i < pFList.Count; i++)
                {
                    IFeature pFeature = pFList[i];
                    for (int j = 0; j < pFeature.Fields.FieldCount; j++)
                    {
                        pAttributeForm.dataGridView1[j, i].Value = pFeature.get_Value(j).ToString();
                    }
                }
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                pAttributeForm.Show();
            }
            else
            {
                MessageBox.Show("未查询到数据");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (pGraphicsContainer != null)
            {
                pGraphicsContainer.DeleteAllElements();
            }
            IActiveView pActiveView = axMapControl1.ActiveView;
            for (int i = 0; i < axMapControl1.LayerCount; i++)
            {
                IFeatureLayer pFeaturelayer = axMapControl1.get_Layer(i) as IFeatureLayer;
                ClearSelectedMapFeatures(pActiveView, pFeaturelayer);
            }
            axMapControl1.Map.ClearSelection();
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            axMapControl1.Refresh();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
        }


    }
}